package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Population;
import com.ruoyi.system.service.IPopulationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人口信息Controller
 * 
 * @author ruoyi
 * @date 2024-10-15
 */
@Controller
@RequestMapping("/system/cz_population")
public class PopulationController extends BaseController
{
    private String prefix = "system/cz_population";

    @Autowired
    private IPopulationService populationService;

    @RequiresPermissions("system:cz_population:view")
    @GetMapping()
    public String cz_population()
    {
        return prefix + "/cz_population";
    }

    /**
     * 查询人口信息列表
     */
    @RequiresPermissions("system:cz_population:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Population population)
    {
        startPage();
        List<Population> list = populationService.selectPopulationList(population);
        return getDataTable(list);
    }

    /**
     * 导出人口信息列表
     */
    @RequiresPermissions("system:cz_population:export")
    @Log(title = "人口信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Population population)
    {
        List<Population> list = populationService.selectPopulationList(population);
        ExcelUtil<Population> util = new ExcelUtil<Population>(Population.class);
        return util.exportExcel(list, "人口信息数据");
    }

    /**
     * 新增人口信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存人口信息
     */
    @RequiresPermissions("system:cz_population:add")
    @Log(title = "人口信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Population population)
    {
        return toAjax(populationService.insertPopulation(population));
    }

    /**
     * 修改人口信息
     */
    @RequiresPermissions("system:cz_population:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Population population = populationService.selectPopulationById(id);
        mmap.put("population", population);
        return prefix + "/edit";
    }

    /**
     * 修改保存人口信息
     */
    @RequiresPermissions("system:cz_population:edit")
    @Log(title = "人口信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Population population)
    {
        return toAjax(populationService.updatePopulation(population));
    }

    /**
     * 删除人口信息
     */
    @RequiresPermissions("system:cz_population:remove")
    @Log(title = "人口信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(populationService.deletePopulationByIds(ids));
    }
}
